import config
import random
from utils import *

def register():
	return RandomChoice()

class RandomChoice:
	def __init__(self):
		self.type = 'passive'
		self.help = \
'''随机选择：
	用法：
		*选择 (选择项1) (选择项2)...
	从给定的选项中随机选择一个。'''

	def run(self, gum, msg):
		if not msg['type'] in ['FriendMessage', 'GroupMessage'] \
				or len(msg['messageChain']) <= 1 \
				or msg['messageChain'][1]['type'] != 'Plain' \
				or msg['messageChain'][1]['text'].split()[0] != '*选择':
			return

		splitted = msg['messageChain'][1]['text'].split()
		if random.random() < 0.1:
			autoReply('糖糖不想选……', gum)
		else:
			autoReply(random.choice(splitted[1:]), gum)